#pragma once

#include <map>
#include <vector>
#include <boost/tuple/tuple.hpp>
#include "MeshUtils.h"
#include "AnimData.h"
#include "AnimNodeData.h"

/** Calculates transformations for a given timestamp from a set of animation tracks. Not directly useful,
 * better use the AnimPlayer class.
 */
class AnimEvaluator
{
public:
	/** Constructor on a given animation. The animation is fixed throughout the lifetime of
	 * the object.
	 * @param pAnim The animation to calculate poses for. Ownership of the animation object stays
	 *   at the caller, the evaluator just keeps a reference to it as long as it persists.
	 */
	AnimEvaluator( const AnimData* data);
	~AnimEvaluator( void);

	/** Evaluates the animation tracks for a given time stamp. The calculated pose can be retrieved as a
	 * array of transformation matrices afterwards by calling GetTransformations().
	 * @param pTime The time for which you want to evaluate the animation, in seconds. Will be mapped into the animation cycle, so
	 *   it can be an arbitrary value. Best use with ever-increasing time stamps.
	 */
	bool Update(DWORD pTime);


	const char* GetAnimationName() {		
		return Anim->mName.c_str();
	}
	

	XMMATRIX* GetAnimTransformation()
	{
		return Transforms;
	}

	int AnimationIndex;

	AnimEvaluator* Clone()
	{
		AnimEvaluator* eval = new AnimEvaluator(Anim);
		eval->AnimationIndex = AnimationIndex;
		return eval;
	}

protected:
	DWORD updateTime;	
	DWORD mLastTime;
	double pTime;
	double accumTime;
	std::vector<boost::tuple<unsigned int, unsigned int, unsigned int> > mLastPositions;
	XMMATRIX* Transforms;
	unsigned int transSize;

	const AnimData* Anim;
	XMVECTOR* pos;
	XMVECTOR* rot;
	XMVECTOR* sca;
};
